﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
using Frame.Pages;


public partial class EditConsumerHis : Frame.Pages.FliterBIEditBasePage<DAL.BLI_ConsumerHis>, IDetailEditManPage<DAL.BLI_ConsumerHis>
{
    protected override Func<DAL.BLI_ConsumerHis, bool> FliterExpression
    {
        get
        {
            if (RefrenceContext<DAL.BI_Consumer>.Current != null)
            {
                return new Func<BLI_ConsumerHis, bool>(
                    o => o.Consumer_ID == RefrenceContext<DAL.BI_Consumer>.Current.Model.ConsumerID
                    );
            }
            else
            {
                return null;
            }
                    
        }
    }
    /// <summary>
    /// 权限编码，需要重新设置
    /// </summary>
    protected override string ActionID
    {
        get { return "0"; }
    }
    protected override void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load(sender, e);
        BackLink.NavigateUrl = (Frame.Pages.RefrenceContext<DAL.BI_Consumer>.Current != null ?
         Frame.Pages.RefrenceContext<DAL.BI_Consumer>.Current.BackUrl : "");
        if (!IsPostBack && !IsCallback)
        {
            if (Frame.Pages.RefrenceContext<DAL.BI_Consumer>.Current != null)
            {
                WebUtility.MappingConsumerView(Detailpanel, RefrenceContext<DAL.BI_Consumer>.Current.Model);
            }
        }

    }
    protected void gridView_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
    {
        e.NewValues["Consumer_ID"] = RefrenceContext<DAL.BI_Consumer>.Current.Model.ConsumerID;
        e.NewValues["AddTime"] = DateTime.Now;
    }
    protected void lbDetail_Click(object sender, EventArgs e)
    {
        LinkButton lb = sender as LinkButton;
        this.BackUrl = "~/ConsumerManage/EditConsumerHis.aspx";
        using (DAL.CMSDALDataContext Datacontext = new CMSDALDataContext())
        {
            BLI_ConsumerHis consumerhis = Datacontext.BLI_ConsumerHis.FirstOrDefault(o=>o.BookNo==lb.CommandArgument);
            this.Model = consumerhis;
        }
        
        RefrenceContext<DAL.BLI_ConsumerHis>.UpdateCurrent(this);
        Response.Redirect(string.Format("~/ConsumerManage/EditConsumerHisDetail.aspx?BookNo={0}",lb.CommandArgument));
    }

    public string BackUrl
    {
        get;
        set;
    }

    public BLI_ConsumerHis Model
    {
        get;
        set;
    }

    public string ScriptBackUrl
    {
        get;
        set;
    }
}